package com.lexue.struts.action;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.lexue.dao.IArea;
import com.lexue.dao.ISubject;
import com.lexue.dao.ITeacherInfo;
import com.lexue.domain.TeacherInfo;
import com.lexue.struts.form.SearchForm;
import com.lexue.struts.form.TeacherPKForm;

public class TeacherPKAction  extends DispatchAction {

	private static final org.apache.commons.logging.Log log = LogFactory
			.getLog(AdminAction.class);

	/*
	 * Generated Methods
	 */

	/**
	 * Method execute
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward pkTeachers(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		//init list
		List areas = areaDAO.findAll();
		List subjects = subjectDAO.findAll();
		request.setAttribute("areas", areas);
		request.setAttribute("subjects", subjects);
		
		TeacherPKForm tpkForm = (TeacherPKForm) form;
		String[] tid = new String[4];
		tid[0] = tpkForm.getTid1();
		tid[1] = tpkForm.getTid2();
		tid[2] = tpkForm.getTid3();
		tid[3] = tpkForm.getTid4();
		
		List teachersList = new ArrayList();
		for(int i = 0 ; i < 4 ; i++)
		{
			try {
				
				TeacherInfo t = teacherDao.queryById(
						new Integer(Integer.parseInt(tid[i])));
				Set subjectSet = t.getSubjects();
				teachersList.add(t);
			} catch (NumberFormatException e) {
				
			}
		}
		request.setAttribute("PkTeacherList", teachersList);
		return  mapping.findForward("show_pk");
	}

	
	
	private ITeacherInfo teacherDao;

	public ITeacherInfo getTeacherDao() {
		return teacherDao;
	}

	public void setTeacherDao(ITeacherInfo t)
	{
		this.teacherDao = t;
	}
	
	private IArea areaDAO;
	private ISubject subjectDAO;

	public IArea getAreaDAO() {
		return areaDAO;
	}

	public void setAreaDAO(IArea areaDAO) {
		this.areaDAO = areaDAO;
	}

	public ISubject getSubjectDAO() {
		return subjectDAO;
	}

	public void setSubjectDAO(ISubject subjectDAO) {
		this.subjectDAO = subjectDAO;
	}

	

}